<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label=" ">
          <el-input v-model="formInline.query" placeholder="请输入姓名、手机号" style="width:230px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <el-button type="primary" @click="contactRead('')">全部已读</el-button>
        <export-excel-button title="联系留言列表" action="/system/contact/list/export" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:operate="{ scope }">
          <el-button type="text" disabled v-if="scope.row.status==2">已读</el-button>
          <el-button @click="contactRead(scope.row.id)" type="text" v-if="scope.row.status==1">未读</el-button>
        </template>
      </ex-table>
    </div>
  </div>
</template>
<script>
  // components
  import {
    contactList,
    contactRead
  } from "@/api/officialWebsite";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import handlePageMixin from "@/mixins/handlePageMixin";
  export default {
    name: "billList",
    components: {
      ExportExcelButton,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        formInline: {
          query: "", //姓名/手机号
        },
        tableData: [],
        tableColumn: [
          {
            prop: "name",
            label: "姓名"
          },
          {
            prop: "region",
            label: "所在区域"
          },
          {
            prop: "phone",
            label: "手机号"
          },
          {
            prop: "product",
            label: "需求产品"
          },
          {
            prop: "question",
            label: "问题简述"
          },
          {
            prop: "createTime",
            label: "提交时间"
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate"
          },
        ],
      };
    },
    computed: {
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        return params;
      },
    },
    mounted() {
      this.getList();
    },
    methods: {
      contactRead(id) {
        let params = {
          id: id
        }
        let title = ''
        if(id==''){
          title = '是否全部已读'
        }else{
          title = '是否已读该消息'
        }
        this.$confirm(title, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          contactRead(params).then((res) => {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
              });
              setTimeout(() => {
                this.reset();
              }, 800);
            });
        }).catch(() => {
          
        });
      },
      search() {
        //搜索
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        contactList(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;
            this.tableData = records;
            this.$refs.table.pageOptions.total = total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
    },
  };

</script>
<style lang="scss">
  .el-card-title {
    font-size: 20px;
  }

</style>
<style lang="scss" scoped>
  .head {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 40px;
  }

  .listBox {
    box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
  }

</style>
